//
//  MYNewfeatureCell.m
//  奇闻
//
//  Created by 似水灵修 on 14-11-24.
//  Copyright (c) 2014年 MingYueGuCheng. All rights reserved.
//

#import "MYNewfeatureCell.h"
#import "MYTabBarController.h"

@interface MYNewfeatureCell ()
@property (nonatomic, weak) UIImageView *imageView;
@property (nonatomic, weak) UIButton *shareButton;//分享
@property (nonatomic, weak) UIButton *shartButton;//开始
@end
@implementation MYNewfeatureCell
- (UIButton *)shareButton
{
    if (nil == _shareButton) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setImage:[UIImage imageNamed:@"new_feature_share_false"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"new_feature_share_true"] forState:UIControlStateSelected];
        [btn setTitle:@"分享之世界" forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(share:) forControlEvents:UIControlEventTouchUpInside];
        [btn sizeToFit];
        [self addSubview:btn];
        _shareButton = btn;
    }
    return _shareButton;
}
- (UIButton *)shartButton
{
    if (nil == _shartButton) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
//        [btn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button"] forState:UIControlStateNormal];
//        [btn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button_highlighted"] forState:UIControlStateHighlighted];
        [btn setTitle:@"开始  探索" forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(shart) forControlEvents:UIControlEventTouchUpInside];
        [btn sizeToFit];
        [self addSubview:btn];
        _shartButton = btn;
    }
    return _shartButton;
}
- (void)shart
{
    MYTabBarController *tabBarVC = [[MYTabBarController alloc] init];
    MYKeyWindow.rootViewController = tabBarVC;
}
- (void)share:(UIButton *)btn
{
    btn.selected = !btn.selected;
}
- (UIImageView *)imageView
{
    if (nil == _imageView) {
        UIImageView *imageView = [[UIImageView alloc] init];
        [self addSubview:imageView];
        self.imageView = imageView;
    }
    return _imageView;
}
- (void)setImage:(UIImage *)image
{
    _image = image;
    self.imageView.image = image;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    self.imageView.frame = self.bounds;
    CGFloat centerX = self.width * 0.5;
    self.shareButton.center = CGPointMake(centerX, self.height * 0.80);
    self.shartButton.center = CGPointMake(centerX, self.height * 0.85);
}
- (void)setIndexPath:(NSIndexPath *)indexPath itemCount:(NSInteger)count
{
    if (indexPath.item == count - 1) {
        self.shareButton.hidden = NO;
        self.shartButton.hidden = NO;
    }
    else {
        self.shareButton.hidden = YES;
        self.shartButton.hidden = YES;
    }
}
@end
